//
//  ZZCSecondBaseViewController.m
//  B段项目
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCSecondBaseViewController.h"

@interface ZZCSecondBaseViewController ()

@end

@implementation ZZCSecondBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //创建返回按钮
    self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.height, self.navigationController.navigationBar.frame.size.height);
    self.backButton.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.backButton];
    
    //创建返回图标放在返回按钮上
    self.backButtonImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.backButton.frame.size.width / 4, self.backButton.frame.size.width / 4, self.backButton.frame.size.width / 2, self.backButton.frame.size.width / 2)];
    self.backButtonImage.image = [UIImage imageNamed:@"iconfont-houtui.png"];
    [self.backButton addSubview:self.backButtonImage];
    
    //返回按钮方法
    [self.backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    //创建一个空View顶替系统LeftBar
    UIView *nilView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:nilView];
    
    //自定义右边View
    self.rightView = [[UIView alloc]initWithFrame:CGRectMake(self.backButton.frame.size.width + 1, 0, self.navigationController.navigationBar.frame.size.width - self.backButton.frame.size.width - 1, self.navigationController.navigationBar.frame.size.height)];
    self.rightView.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.rightView];
    
    //创建label(navigationItem.title)来显示每页标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.rightView.frame.size.height / 4, self.rightView.frame.size.height / 4, self.navigationController.navigationBar.frame.size.width / 5 * 3, self.rightView.frame.size.height / 2)];
    [self.rightView addSubview:self.titleLabel];

}


#pragma mark - 点击返回按钮的时候移除三个NavigationBar上的View
- (void)backAction:(UIButton *)backAction{
   
    [self removeBtns];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)removeBtns
{
    [self.backButton removeFromSuperview];
    [self.rightView removeFromSuperview];
    [self.titleLabel removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
